/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "command_handler_base.h"
#include "utils_log.h"

namespace El {
namespace Protocol {

// 创建错误响应
nlohmann::json CommandHandlerBase::CreateErrorResponse(const std::string &id,
                                                     int code,
                                                     const std::string &message,
                                                     const nlohmann::json &data)
{
    nlohmann::json error = {{"code", code}, {"message", message}};

    if (data != nullptr) {
        error["data"] = data;
    }

    nlohmann::json response = {{"id", id}, {"error", error}};

    return response;
}

// 创建成功响应
nlohmann::json CommandHandlerBase::CreateSuccessResponse(const std::string &id, const nlohmann::json &result)
{
    return {{"id", id}, {"result", result}};
}

} // namespace Protocol
} // namespace El